package com.mobileares.midp.widgets.client.page;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by IntelliJ IDEA.
 * User: Tom
 * Date: 2010-6-9
 * Time: 16:50:04
 * To change this template use File | Settings | File Templates.
 */
public class MenuModel extends ItemModel {
    private String text;
    //栏目条目标示,判断MenuModel是否为同一个的的条件。
    private String code;
    private List<PageModel> pages;
    //栏目条目排序，9999为默认排序，如果模型中index重复，则以同序列中默认排序

    private Object userObject;

    private List<AbstractAccess> accesses;

    public void addAccess(AbstractAccess access) {
        if (accesses == null)
            accesses = new ArrayList();
        accesses.add(access);
    }

    public void removeAccess(AbstractAccess access) {
        if (accesses != null)
            accesses.remove(access);
    }

    public List<AbstractAccess> getAccesses() {
        return accesses;
    }

    public void setAccesses(List<AbstractAccess> accesses) {
        this.accesses = accesses;
    }

    public MenuModel(String text) {
        this(text, text);
    }

    public MenuModel(String text, String code) {
        this.text = text;
        this.code = code;
    }

    public MenuModel(String text, int index) {
        this(text, text);
        setIndex(index);
    }

    public String getText() {
        return text;
    }

    public void setText(String text) {
        this.text = text;
    }

    public String getCode() {
        return code;
    }

    public void setCode(String code) {
        this.code = code;
    }


    public List<PageModel> getPages() {
        return pages;
    }

    public void setPages(List<PageModel> pages) {
        this.pages = pages;
    }

    public Object getUserObject() {
        return userObject;
    }

    public void setUserObject(Object userObject) {
        this.userObject = userObject;
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (o == null || getClass() != o.getClass()) return false;

        MenuModel menuModel = (MenuModel) o;

        if (code != null ? !code.equals(menuModel.code) : menuModel.code != null) return false;

        return true;
    }
}
